/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import com.bourre.data.iterator.ArrayIterator;
import com.bourre.data.iterator.Iterator;
import com.bourre.events.EventType;

import fever.events.AbstractEvent;

import fvaswing.components.FvFileChooser;
import fever.data.file.File;

/**
 * Event structure with {@link fvaswing.components.FvFileChooser} 
 * result.
 *
 * @author Romain Ecarnot
 */
class fvaswing.components.filechooser.events.FvFileChooserEvent extends AbstractEvent
{
	//-------------------------------------------------------------------------
	// Events definition
	//-------------------------------------------------------------------------
	
	/** Dispatches when user close the chooser dialog. */
	public static var onFileChooserEVENT : EventType = new EventType( 'onFileChooser' );
	
	
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _files : Array;	private var _path : String;
	private var _type : Number;
	
		
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	public function FvFileChooserEvent( t : Number, files : Array, path : String )
	{
		super( FvFileChooserEvent.onFileChooserEVENT );
		
		_type = t;
		_files = files;
		_path = _path;
	}
	
	/**
	 * Returns event target
	 */
	public function getTarget() : FvFileChooser
	{
		return FvFileChooser( _oT );	
	}
	
	/**
	 * Returns chooser close ID.
	 * 
	 * <p>can be
	 * <ul>
	 *   <li>{@link fvaswing.components.FvFileChooser#APPROVE_OPTION} if the user approved</li>
	 *   <li>{@link fvaswing.components.FvFileChooser#CANCEL_OPTION} if the user cancelled it</li>
	 *   <li>{@link fvaswing.components.FvFileChooser#ERROR_OPTION}, which means an unanticipated error occurred</li>
	 * </ul>
	 */
	public function getResult() : Number
	{
		return _type;	
	}
	
	/**
	 * Returns selected file.
	 * 
	 * <p>Used when {@link fvaswing.components.FvFileChooser#setMultiSelectionEnabled} 
	 * is disabled.
	 * 
	 * @return Full qualified filename
	 */
	public function getSelectedFile() : File
	{
		return _files[0];
	}
	
	/**
	 * Returns selected file.
	 * 
	 * <p>Used when {@link fvaswing.components.FvFileChooser#setMultiSelectionEnabled} 
	 * is enabled.
	 * 
	 * @return Array structure
	 */
	public function getSelectedFiles() : Array
	{
		return _files;
	}
	
	/**
	 * Retuns array iterator over files array.
	 */
	public function getFilesIterator() : Iterator
	{
		return new ArrayIterator( _files );	
	}
	
	/**
	 * Returns full pathname.
	 */
	public function getPath() : String
	{
		return _path;	
	}
	
}